const app = getApp()

Page({

  data: {
    stars: [0, 1, 2, 3, 4],
    normalSrc: '/images/@2x_star_b.png',
    selectedSrc: '/images/@2x_star_y.png',
    key: 0, //评分
    userInput: '',
    course_id: ''
  },

  onLoad(options) {
    let that = this;
    that.setData({
      course_id: options.id,
    })
    //console.log(that.data.course_id)
  },

  //点击选择整颗星评分
  selectRight: function (e) {
    var key = e.currentTarget.dataset.key
    console.log("得" + key + "分")
    this.setData({
      key: key
    })
  },

  textAreaCon: function (e) {
    var that = this;
    that.setData({
      userInput: e.detail.value,
    })
  },

  saveAccess: function (e) {
    let that = this;
    if (that.data.userInput == '') {
      wx.showModal({
        title: '提示',
        content: '对不起，请输入留言内容',
      })

    } else {
      console.log(that.data.userInput);
      //  成功监听用户输入内容
      //提交
      wx.request({
        url: 'http://localhost:8888/sfzy/CourseMark',
        method: 'POST',
        data: {
          user_id: app.globalData.point.id,
          course_id: that.data.course_id,
          content: that.data.userInput,
          grade: that.data.key,
        },
        success(res) {
          console.log("评价成功")
          wx.showToast({
            title: '成功',
            icon: 'success',
            duration: 2000, //持续的时间
            mask:true,
            //显示透明蒙层，防止触摸穿透
            success: function () {
              setTimeout(function () {
                //要延时执行的代码
                  wx.navigateTo({
                    url: '/pages/course/coursedetail/coursedetail?id='+that.data.course_id,
                 })
              }, 1500) //延迟时间
            }
          })
        }
      })
    }
  }
})